package cn.edu.jxau.core.process.spectrumutil;

import cn.edu.jxau.core.vo.SpectrumFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
/**
 * 反序列化取得SpectrumFile对象
 * @author 巫发萍
 * spectrum3
 * 2017年8月27日
 */
public class GetSpectrum {
    private static Logger logger = LoggerFactory.getLogger(GetSpectrum.class);
	/**
	 * 传入绝对路径
	 *@author 巫发萍
	 * @param absolutePath
	 * @return
	 */
	public static SpectrumFile parcelagle(String absolutePath) {
		return parcelagle(new File(absolutePath));
	}

	/**
	 * 传入File对象
	 *@author 巫发萍
	 * @param file
	 * @return
	 */
	public static SpectrumFile parcelagle(File file) {
		if (file == null || !file.exists()) return null;
		SpectrumFile spectrumfile = null;
		ObjectInputStream inputStream = null;
        try {
            inputStream = new ObjectInputStream(new FileInputStream(file));
            try {
            	spectrumfile = (SpectrumFile) inputStream.readObject();
                logger.debug("执行反序列化过程成功。" + spectrumfile.getFileName());
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
		return spectrumfile;
	}

}
